// ignore_for_file: file_names, must_be_immutable

import 'package:flutter/material.dart';

class MyApp14 extends StatelessWidget {
  MyApp14({super.key});

  List<Widget> getChildren() {
    return [1, 2, 3, 4, 5, 6, 7, 9, 10].map((int value) {
      return Container(
        alignment: Alignment.center,
        color: Colors.teal,
        child: Text(
          '第$value个',
          style: TextStyle(color: Colors.white, fontSize: 30),
        ),
      );
    }).toList();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        //1.导航
        appBar: AppBar(
          title: const Text('GridView组件'),
          backgroundColor: Colors.pink,
        ),
        //2.内容
        body: Padding(
          padding: EdgeInsets.all(10),
          child: GridView(
            //代理1
            //SliverGridDelegateWithFixedCrossAxisCount 一行的个数是固定的 无论横屏还是竖屏
            // gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            //   crossAxisCount: 3, //列数
            //   childAspectRatio: 1.5, //宽高比
            //   mainAxisSpacing: 10, //主轴间距
            //   crossAxisSpacing: 10, //列间距
            // ),

            //代理2
            //SliverGridDelegateWithMaxCrossAxisExtent 一行的宽高是固定的 无论横屏还是竖屏
            gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
              maxCrossAxisExtent: 200, //最大宽度
              childAspectRatio: 1.5, //宽高比
              mainAxisSpacing: 10, //行间距
              crossAxisSpacing: 10, //列间距
            ),
            children: getChildren(),
          ),
        ));
  }
}
